package com.seven.webhook.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.seven.webhook.model.MonitorGroup;
import com.seven.webhook.mapper.MonitorGroupMapper;
import com.seven.webhook.model.MonitorRule;
import com.seven.webhook.service.MonitorGroupService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.seven.webhook.service.MonitorRuleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author seven
 * @since 2020-11-09
 */
@Service
public class MonitorGroupServiceImpl extends ServiceImpl<MonitorGroupMapper, MonitorGroup>
        implements MonitorGroupService {

    @Autowired
    MonitorRuleService monitorRuleService;

    @Override
    public List<MonitorGroup> list() {
        List<MonitorGroup> list = super.list();
        list.forEach(s -> {
            List<MonitorRule> monitorRuleList = monitorRuleService.list(new QueryWrapper<MonitorRule>().lambda()
                    .eq(MonitorRule::getMonitorGroupId, s.getId()));
            s.setMonitorRules(monitorRuleList);
        });
        return list;
    }
}
